package com.ugoodtech.mdcc.core.repository;

import com.ugoodtech.mdcc.core.domain.StationLeanPaintSatisfactionReport.OverallOperations;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface OverallOperationsRepository extends PagingAndSortingRepository<OverallOperations, Long>
        , QueryDslPredicateExecutor<OverallOperations> {

    @Query(value = "select date_format(creation_time,'%Y%m'),brankStationMaxCapacity_A,brankStationMaxCapacity_Face,brankStationUtilization,personMaxCapacity_A,personMaxCapacity_Face,workersUtilization," +
            "stationMaxCapacity_A,stationMaxCapacity_Face,stationUtilization from overallOperations where stationId=:stationId order by creation_time limit 0,7", nativeQuery = true)
    List<Object[]> selectRepoty(@Param("stationId") Long stationId);


    @Query("select date_format(max(creation_time),'%Y%m'),improvementTimStr from OverallOperations where stationId=:stationId")
    List<Object[]> getMonth(@Param("stationId") Long stationId);

    @Query(value = "select '',brankStationMaxCapacity_A,brankStationMaxCapacity_Face,brankStationUtilization,personMaxCapacity_A,personMaxCapacity_Face,workersUtilization," +
            "stationMaxCapacity_A,stationMaxCapacity_Face,stationUtilization,index_id from overallOperations where reportId=:reportId and stationId=:stationId and deleted=false and enabled=true", nativeQuery = true)
    List<Object[]> getDataKpi(@Param("reportId") Long reportId, @Param("stationId") Long stationId);


}
